package com.zeng.jiudian.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author JJ_yo
 * @Date 2020/8/5 - 16:31
 */
public class MyBatisFactory
{
    public static SqlSessionFactory getSqlSessionFactory() throws IOException
    {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);

        return new SqlSessionFactoryBuilder().build(inputStream);
    }

    public static SqlSession getSqlSession() throws IOException
    {
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();

        return sqlSessionFactory.openSession(true);
    }
}
